<?php
include_once dirname(dirname(dirname(__FILE__))).'/include/db_connect.php';

function getUserRuleId() {
	$conn = get_db_conn();
	$sql = 'select id from user_rule limit 0,1';
	$result = mysql_query($sql,$conn) or die("db error");
	if(mysql_num_rows($result)==0) {
		$sql = 'insert into user_rule(update_time) values("'.date('Y-m-d H:i:s').'");';
		mysql_query($sql,$conn) or die("db error");
		$sql = 'select id from user_rule limit 0,1';
		$result = mysql_query($sql,$conn) or die("db error");
	}
	$row = mysql_fetch_array($result);
	return $row['id'];
}

function updateUserRule($content,$user_id) {
	$conn = get_db_conn();
	$sql = 'update user_rule set content = "'.$content.'" ,author_id = '.$user_id.
			',update_time = "'.date('Y-m-d H:i:s').'" where id = '.getUserRuleId().';';
	mysql_query($sql,$conn) or die("db error");
	return true;
}

function getUserRule() {
	$conn = get_db_conn();
	$id = getUserRuleId();
	$sql = 'select * from user_rule where id = '.$id.' limit 0,1;';
	$result = mysql_query($sql,$conn) or die("db error");
	$row = mysql_fetch_array($result);
	return $row;
}